export function countTime(startTime, endTime) {
  let sTime = Date.parse(new Date(startTime));
  let eTime = Date.parse(new Date(endTime));
  let useTime = eTime - sTime;
  let leave = useTime % (24 * 3600 * 1000);
  let hours = leave / (3600 * 1000);
  return hours;
}
export function transformTime(time) {
  const date = new Date(time);
  const Y = date.getFullYear() + "-";
  const M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  const D =
    date.getDate() < 10 ? "0" + date.getDate() + " " : date.getDate() + " ";
  const h =
    date.getHours() < 10 ? "0" + date.getHours() + ":" : date.getHours() + ":";
  const m =
    date.getMinutes() < 10
      ? "0" + date.getMinutes() + ":"
      : date.getMinutes() + ":";
  const s =
    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return Y + M + D + h + m + s;
}

// 停留时长
export function timediff(begin_time: string, end_time: string) {
  if (typeof begin_time === "string" && typeof end_time === "string") {
    let beginTime = new Date(begin_time).getTime() / 1000;
    let endTime = new Date(end_time).getTime() / 1000;
    let starttime = 0;
    let endtime = 1;
    if (beginTime < endTime) {
      starttime = beginTime;
      endtime = endTime;
    } else {
      starttime = endTime;
      endtime = beginTime;
    }
    //计算天数
    let timediff = endtime - starttime;
    let remain = timediff % 86400;
    let hours = parseInt(remain / 3600);
    //计算分钟数
    remain = remain % 3600;
    let mins = parseInt(remain / 60);
    let res = hours + "小时" + mins + "分";
    return res;
  } else {
    return "-";
  }
}
